package org.edu.modules.stu.stu.service.impl;

import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.utils.ConvertUtils;
import org.edu.modules.stu.base.dto.VeBaseStudentDto;
import org.edu.modules.stu.base.service.VeBaseStudentService;
import org.edu.modules.stu.stu.mapper.HqStuPositionApplyMapper;
import org.edu.modules.stu.stu.entity.HqStuPositionApply;
import org.edu.modules.stu.stu.dto.HqStuPositionApplyDto;
import org.edu.modules.stu.stu.service.HqStuPositionApplyService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;
import java.util.Map;


/**
 * 实现类
 */
@Service
public class HqStuPositionApplyServiceImpl extends BaseServiceImpl<HqStuPositionApply, HqStuPositionApplyMapper> implements HqStuPositionApplyService {

    @Autowired
    private VeBaseStudentService veBaseStudentService;

    public IPage<HqStuPositionApplyDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper) {
        return mapper.pageDto(page, queryWrapper);
    }

    @Override
    public IPage<HqStuPositionApplyDto> pageDtoByUserId(BasePageDto page, Wrapper queryWrapper, String userId) {
        return mapper.pageDtoByUserId(page, queryWrapper, userId);
    }

    /**
     * 查询实体类
     */
    public HqStuPositionApplyDto findDtoById(String id) {
        HqStuPositionApply entity = super.findById(id);
        HqStuPositionApplyDto dto = ConvertUtils.convertToDto(entity, HqStuPositionApplyDto.class);
        return dto;
    }

    /**
     * 新增或者修改
     */
    public void insertOrUpdate(HqStuPositionApplyDto dto, Boolean isAdd) {
        if (isAdd) {
            //根据学号查学生信息
            VeBaseStudentDto baseStudent = veBaseStudentService.findDtoByXh(dto.getCode());
            if (baseStudent != null) {
                dto.setStuId(baseStudent.getId());
                dto.setTerminalId(1);
            }
            super.insert(dto);
        } else {
            super.update(dto);
        }
    }

    @Override
    public void importExcel(List<Map<String, Object>> mapList) {
        for (Map map : mapList) {
            HqStuPositionApplyDto dto = new HqStuPositionApplyDto();
            //         dto.setStuId ((String)map.get(0000));
            //         dto.setPositionId ((String)map.get(0000));
            //         dto.setContent ((String)map.get(0000));
            //         dto.setStatus ((String)map.get(0000));
            //         dto.setApplyTime ((String)map.get(0000));
            //         dto.setAuditTime ((String)map.get(0000));
            //         dto.setAuditUserId ((String)map.get(0000));
            //         dto.setAuditUserName ((String)map.get(0000));

            super.insert(dto);
        }

    }

}
